<?php
/*
	收入明细
*/
defined('BY_JYA') or exit('error');
$_RQ['op']=$_RQ['op']?$_RQ['op']:'list';
if($_RQ['op']=='list'){
	$params=array('status'=>1,'fee OR'=>'fee>0 or fee<=0');
	$params['uniacid']=$_SESSION['uniacid'];
	$params2=array('buy_time OR'=>'buy_time>0 or ding_time>0','uniacid'=>$_SESSION['uniacid']);
	if($_SESSION['storeids']){
		$params['storeid']=$_SESSION['storeids'];
		$params2['storeid']=$_SESSION['storeids'];
	}
	if($_RQ['storeid']){
		$params['storeid']=$_RQ['storeid'];
		$params2['storeid']=$_RQ['storeid'];
		$return['params']['storeid']=$_RQ['storeid'];
	}
	if($_RQ['juese']){
		$return['params']['juese']=$_RQ['juese'];
	}
	if($_RQ['title']){
		$params2['title like']='%'.trim($_RQ['title']).'%';
		$memberids=pdo_getall('jy_yxw_member',$params2,'id','id');
		if($memberids){
			$memberids=array_keys($memberids);
		}else{
			$memberids=-1;
		}
		$params['memberid']=$memberids;
		$return['params']['title']=$_RQ['title'];
	}
	if($_RQ['cardno']){
		$params2['cardno like']='%'.trim($_RQ['cardno']).'%';
		$memberids=pdo_getall('jy_yxw_member',$params2,'id','id');
		if($memberids){
			$memberids=array_keys($memberids);
		}else{
			$memberids=-1;
		}
		$params['memberid']=$memberids;
		$return['params']['cardno']=$_RQ['cardno'];
	}
	if($_RQ['mstatus']){
		$params2['status']=$_RQ['mstatus'];
		$memberids=pdo_getall('jy_yxw_member',$params2,'id','id');
		if($memberids){
			$memberids=array_keys($memberids);
		}else{
			$memberids=-1;
		}
		$params['memberid']=$memberids;
		$return['params']['cardno']=$_RQ['cardno'];
	}
	if($_RQ['jiao_day']){
		$params['jiao_day']=$_RQ['jiao_day'];
		$return['params']['jiao_day']=$_RQ['jiao_day'];
	}
	if($_RQ['zhanghu']){
		$params['zhanghu']=$_RQ['zhanghu'];
		$return['params']['zhanghu']=$_RQ['zhanghu'];
	}
	if($_RQ['type']){
		$params['type']=$_RQ['type']-1;
		$return['params']['type']=$_RQ['type'];
	}
	if($_RQ['worker5id']){
		$params['worker5id']=$_RQ['worker5id'];
		$return['params']['worker5id']=$_RQ['worker5id'];
	}
	if($_RQ['worker6id']){
		$params['worker6id OR']='worker6id='.$_RQ['worker6id'].' or workerheid='.$_RQ['worker6id'];
		$return['params']['worker6id']=$_RQ['worker6id'];
	}
	//创建时间
	if($_RQ['jiao_time']){
		$time_range=cfc('tools')->base64_decode($_RQ['jiao_time'],$_SESSION['base_key_str']);
		$time_range=json_decode($time_range,true);
		$return['params']['jiao_time']=$time_range;
		$params['jiao_time between']=array($time_range['tstart'],$time_range['tend']);
	}
	$pindex = max(1, intval($_RQ['page']));
	$psize = $_RQ['psize']?:30;
	if($_RQ['psize']){
		$return['params']['psize']=$_RQ['psize'];
	}
	$total='';
	$list=pdo_getslice('jy_yxw_feelog',$params,array($pindex,$psize),$total,$fields,'','jiao_time desc, id desc');
	if($list){
		$fee=$fee2=$fee3=$shouhoufee=$zufee=$peifee=$zhaofee=0;
		foreach($list as &$item){
			$item['member']=$this->model('member')->member_show($item['memberid']);
			$member=pdo_get('jy_yxw_member',array('id'=>$item['memberid'],'uniacid'=>$_SESSION['uniacid']),array('title','status','cardno','worker5id','worker6id','workerheid'));
			$item['cardno']=$member['cardno'];
			$item['mstatus']=$member['status'];
			$item['zhanghu']=$item['zhanghu']?:'公户';
			$item['storetitle']=pdo_getcolumn('jy_yxw_store',array('uniacid'=>$_SESSION['uniacid'],'id'=>$item['storeid']),'title');
			$item['worker5title']=pdo_getcolumn('jy_yxw_worker',array('uniacid'=>$_SESSION['uniacid'],'id'=>$member['worker5id']),'title');
			$item['worker6title']=pdo_getcolumn('jy_yxw_worker',array('uniacid'=>$_SESSION['uniacid'],'id'=>$member['worker6id']),'title');
			if($member['workerheid'] && !$item['workerheid']){
				pdo_update('jy_yxw_feelog',array('workerheid'=>$member['workerheid']),array('id'=>$item['id'],'uniacid'=>$_SESSION['uniacid']));
			}
			$workerhe=pdo_get('jy_yxw_worker',array('uniacid'=>$_SESSION['uniacid'],'id'=>$member['workerheid']),array('juese','title'));
			if($workerhe['title']){
				$item['workerhetitle']=$this->user_juese[$workerhe['juese']].':'.$workerhe['title'];
			}
			$item['createtime']=date('Y-m-d',$item['createtime']);
			$item['jiao_day']=date('Y-m-d',$item['jiao_time']);
			if(!$item['infeeid'] && $item['tuifeeid']){
				$item['infeeid']=pdo_getcolumn('jy_yxw_tuifee_log',array('id'=>$item['tuifeeid'],'uniacid'=>$_SESSION['uniacid']),'infeeid');
			}
			$infee_log=pdo_get('jy_yxw_infee_log',array('id'=>$item['infeeid'],'uniacid'=>$_SESSION['uniacid']));
			$item['infeetype']=$infee_log['type'];
			$item['infeestatus']=$infee_log['status'];
			$item['peifee']=$infee_log['peifee'];
			$item['bufee']=$infee_log['bufee'];
			$item['pay_type']=$infee_log['pay_type'];
			$item['daipay_type']=$infee_log['daipay_type'];
			if($item['type']==1){
				$item['fee']=$item['fee']+$item['bufee'];
				//$item['fee']=0;
			}elseif($item['type']==2){
				$item['fee2']=$item['fee'];
				//$item['fee']=0;
			}elseif($item['type']==3){
				$item['fee3']=$item['fee'];
				//$item['fee']=0;
			}
			$item['zufee']=$item['zufee']>0?$item['zufee']:price($item['fee']*16/100,'int');
			$fee +=$item['fee'];
			$fee2 +=$item['fee2'];
			$fee3 +=$item['fee3'];
			$shouhoufee +=$item['shouhoufee'];
			$zufee +=$item['zufee'];
			$peifee +=$item['peifee'];
			$zhaofee +=$item['zhaofee'];
		}
		$fee=price($fee,'int');
		$fee2=price($fee2,'int');
		$fee3=price($fee3,'int');
		$shouhoufee=price($shouhoufee,'int');
		//$zufee=price($zufee,'int');
		$peifee=price($peifee,'int');
		$zhaofee=price($zhaofee,'int');
		$list[]=array('storetitle'=>'合计','fee'=>$fee,'fee2'=>$fee2,'fee3'=>$fee3,'shouhoufee'=>$shouhoufee,'zufee'=>$zufee,'peifee'=>$peifee,'zhaofee'=>$zhaofee);
	}
	$return['list']=$list;
	$totalpage=ceil($total/$psize);
	$totalpage=intval($totalpage);
	$return['totalpage'] =$totalpage;
	$return['params']['page'] =$pindex;
	$htmls=array(
		'type'=>'list',
		'export'=>'export',
		'tabs'=>$tabs,
		'list'=>array('data'=>'list','tip'=>'[<red>温馨提示</red>]：收入主要包括金额（包含单费+补贴）(定金	单费	退款收费)入账！','total'=>$total,'psize'=>$psize,'edit'=>false,'del_one'=>false,'delall'=>false,'list'=>array(
			array('name'=>'storetitle','title'=>'所属门店','type'=>'string'),
			array('name'=>'member','title'=>'姓名','type'=>'member'),
			array('name'=>'cardno','title'=>'身份证号','type'=>'string'),
			array('name'=>'createtime','title'=>'申请日期','type'=>'string'),
			array('name'=>'mstatus','title'=>'状态','type'=>'radio2','options'=>'mstatus'),
			array('name'=>'type','title'=>'收费类型','type'=>'radio2','options'=>'type'),
			array('name'=>'fee','title'=>'金额','type'=>'string'),
			//array('name'=>'fee3','title'=>'退款收费','type'=>'string'),
			array('name'=>'pay_type','title'=>'支费方式','type'=>'radio2','options'=>'pay_types'),
			array('name'=>'daipay_type','title'=>'贷款渠道','type'=>'radio2','options'=>'daipay_types','show'=>array('pay_type'=>array(2,3))),
			array('name'=>'jiao_day','title'=>'交费日期','type'=>'string'),
			array('name'=>'zhanghu','title'=>'到账账户','type'=>'string'),
			array('type'=>'img_string','title'=>'合作成交',
            'data'=>array(
                array('title'=>'销售员:','name'=>'worker6title'),
                array('title'=>'','name'=>'workerhetitle'),
                )
            ),
			array('name'=>'worker5title','title'=>'电客','type'=>'string'),
			array('name'=>'shouhoufee','title'=>'售后成本','type'=>'string'),
			array('name'=>'zufee','title'=>'补贴费','type'=>'string'),
		),'batch'=>array(
			//array('type'=>'href','url'=>'/juese14.in/export/','title'=>'选择月份导出'),
		),'action'=>array()
		),
		'search'=>array(
			array('name'=>'jiao_time','width'=>15,'title'=>'交费日期','type'=>'time_range'),
			array('name'=>'storeid','width'=>10,'title'=>'所属门店','type'=>'select','options'=>'stores'),
			array('name'=>'title','width'=>10,'title'=>'姓名','type'=>'string'),
			array('name'=>'cardno','width'=>10,'title'=>'身份证号','type'=>'string'),
			//array('name'=>'mstatus','width'=>10,'title'=>'状态','type'=>'radio','options'=>'mstatus'),
			//array('name'=>'jiao_day','width'=>10,'title'=>'交费日期','type'=>'time','time_type'=>'day'),
			array('name'=>'zhanghu','width'=>10,'title'=>'到账账户','type'=>'string'),
			array('name'=>'type','width'=>10,'title'=>'收费类型','type'=>'radio','options'=>'type2'),
			array('title'=>'电客员','width'=>10,'name'=>'worker5id','type'=>'select','options'=>'workers5'),
			array('title'=>'销售员','width'=>10,'name'=>'worker6id','type'=>'select','options'=>'workers6'),
		)
	);
	if($_RQ['juese']==17 || $_RQ['juese']==14){
		$htmls['list']['list']['action'][]=array('type'=>'href','action'=>'jy_yxw/juese14.in/jiaofee1/','title'=>'修改信息','show'=>array('type'=>array(0)));
		$htmls['list']['list']['action'][]=array('type'=>'href','action'=>'jy_yxw/juese14.in/jiaofee2/','title'=>'修改信息','show'=>array('type'=>array(1)));
		$htmls['list']['list']['action'][]=array('type'=>'href','action'=>'/juese14.in/fenfeeset/','title'=>'处理异常分期','show'=>array('type'=>array(2)));
		$htmls['list']['list']['action'][]=array('type'=>'href','action'=>'/juese14.in/fenfeeset/','title'=>'处理异常贷款','show'=>array('type'=>array(7)));
	}
	$params=array('uniacid'=>$_SESSION['uniacid']);
	if($_SESSION['storeids']){
		$params['id']=$_SESSION['storeids'];
	}
	$return['workers6']=$this->model('worker')->getworkers(6);
	$return['workers5']=$this->model('worker')->getworkers(5);
	$return['stores']=$this->getall('store',$params,array('id','title'),'id');
	$return['htmls']=$htmls;
	$return['type']=$this->feelog_type;
	$return['type2']=$this->feelog_type2;
	unset($return['type2'][6]);
	$return['mstatus']=$this->member_status;
	$return['pay_types']=$this->pay_types;
	$return['daipay_types']=$this->daipay_types;
	exi($return);
}
if($_RQ['op']=='jiaofee1'){
	if($_RQ['postdata']){
		$post=get_postdata();
		if($post['status']==1 && (!$post['fee'] || $post['fee']<=0)){
			exi('请先输入【确认成交费用】!','error');
		}
		if($post['status']==1 && !$post['jiao_day']){
			exi('请先输入【缴费日期】!','error');
		}
		$id=$post['id'];
		$data=array(
			'fee'=>$post['fee'],
			'classid'=>$post['classid'],
			'remark'=>trim($post['remark']),
			'pay_type'=>intval($post['pay_type']),
			'daipay_type'=>intval($post['daipay_type']),
			'dai_time'=>intval($post['dai_time']),
			'dai_sn'=>trim($post['dai_sn']),
			'status'=>intval($post['status']),
			'zhanghu'=>trim($post['zhanghu']),
			'bufee'=>trim($post['bufee']),
			'zufee'=>trim($post['zufee']),
			'peifee'=>trim($post['peifee']),
			'zhaofee'=>trim($post['zhaofee']),
			'jiao_day'=>trim($post['jiao_day']),
			'jiao_time'=>strtotime($post['jiao_day']),
			'shouhoufee'=>$post['shouhoufee'],
			'hefee'=>trim($post['hefee']),
		);
		$data['uniacid']=$_SESSION['uniacid'];
		$data['up_time']=time();
		$data['up_workerid']=$_SESSION['workerid'];
		if(!$data['shoustoreid'] && $post['status']==1){
			$data['shoustoreid']=pdo_getcolumn('jy_yxw_yonghu',array('uniacid'=>$_SESSION['uniacid'],'memberid'=>$post['memberid']),'storeid');
		}
		$this->update('infee_log',$data,array('id'=>$id));
		if($post['status']==1){
			$update=array('status'=>10);
			if($post['shouhoufee']>0){
				$update['shouhoufee']=$post['shouhoufee'];
			}
			if($post['bufee']>0){
				$update['bufee']=$post['bufee'];
				$update['lastbufee']=$post['bufee'];
			}
			$uplog=array(
				'memberid'=>$post['memberid'],
				'remark'=>'财务审核成交通过',
				'status'=>1,
				'type'=>2,
			);
			$this->model('uplog')->addgenjin_log($uplog);
			pdo_update('jy_yxw_member',$update,array('uniacid'=>$_SESSION['uniacid'],'id'=>$post['memberid']));
			$this->model('uplog')->upfenfee_log($post);
			$this->model('feelog')->upfeelog($id,'',0);
		}
		if($post['status']==2){
			$uplog=array(
				'memberid'=>$post['memberid'],
				'remark'=>'财务审核成交不通过',
				'status'=>1,
				'type'=>2,
			);
			$this->model('uplog')->addgenjin_log($uplog);
			$this->model('uplog')->delfenfee_log($post);
			$this->model('feelog')->delfeelog($post);
			pdo_update('jy_yxw_member',array('status'=>38),array('uniacid'=>$_SESSION['uniacid'],'id'=>$post['memberid']));
		}
		exi('操作成功！','','goback');
	}
	if($_RQ['id']){
		$feelog=pdo_get('jy_yxw_feelog',array('id'=>$_RQ['id'],'uniacid'=>$_SESSION['uniacid']));
		$item=pdo_get('jy_yxw_infee_log',array('uniacid'=>$_SESSION['uniacid'],'id'=>$feelog['infeeid']));
		$item['fen_log']=json_decode($item['fen_log'],true);
		$item['fen_file']=json_decode($item['fen_file'],true);
		$member=pdo_get('jy_yxw_member',array('uniacid'=>$_SESSION['uniacid'],'id'=>$item['memberid']));
		$item['title']=$member['title'];
		$item['mobile']=$member['mobile'];
		$item['cardno']=$member['cardno'];
		$item['xueli']=$member['xueli'];
		$item['classtitle']=pdo_getcolumn('jy_yxw_class',array('uniacid'=>$_SESSION['uniacid'],'id'=>$item['classid']),'title');
		if(!$item['storeid']){
			$item['storeid']=$member['storeid'];
			$this->update('infee_log',array('storeid'=>$item['storeid']),array('uniacid'=>$_SESSION['uniacid'],'id'=>$_RQ['id']));
		}
		$item['storetitle']=pdo_getcolumn('jy_yxw_store',array('uniacid'=>$_SESSION['uniacid'],'id'=>$item['storeid']),'title');
	}else{
		exi('请先选择记录','error');
	}
	if($item['fen_log']){
		foreach($item['fen_log'] as &$fv){
			$fv['timenum']=strtotime($fv['time']);
		}
		paixu($item['fen_log'],'timenum','asc');
		foreach($item['fen_log'] as $k=>&$nfv){
			$sn=$k+1;
			$nfv['sn']='第'.$sn.'期';
		}
	}
	$item['zhanghu']=$item['zhanghu']?:'公户';
	$item['xueli']=$this->xueli_type[$item['xueli']];
	$item['pay_typetitle']=$this->pay_types[$item['pay_type']];
	$item['daipay_typetitle']=$this->daipay_types[$item['daipay_type']];
	$return['item']=$item;
	if($member['workerheid']){
		$workerhe=pdo_get('jy_yxw_worker',array('uniacid'=>$_SESSION['uniacid'],'id'=>$member['workerheid']),array('juese','title'));
		$workerhetitle=$this->user_juese[$workerhe['juese']].':'.$workerhe['title'];
	}
	$htmls=array(
		'type'=>'edit',
		'desc'=>'售后成交',
	);
	$htmls['edit']=array(
		array('type'=>'copy','title'=>'所属门店','name'=>'storetitle'),
		array('type'=>'string_three','title1'=>'售后姓名','title2'=>'身份证','title3'=>'手机','name1'=>'title','name2'=>'cardno','name3'=>'mobile','read'=>true),
		array('type'=>'string_three','title1'=>'学历','title2'=>'售后成本','name1'=>'xueli','name2'=>'shouhoufee','read1'=>true),
		array('type'=>'string_three','title1'=>'成交费','title2'=>'缴费方式','title3'=>'缴费渠道','name1'=>'tofee','name2'=>'pay_typetitle','name3'=>'daipay_typetitle','read'=>true),
		array('type'=>'string_three','title1'=>'确认成交费用','title2'=>'到账账户','name1'=>'fee','name2'=>'zhanghu'),
		//array('type'=>'string_three','title1'=>'补贴费用','title2'=>'补贴费费','title3'=>'售后费用','name1'=>'bufee','name2'=>'zufee','name3'=>'peifee'),
		//array('name'=>'bufee','title'=>'补贴费费用','type'=>'unitstring','unit'=>'元'),
		array('type'=>'unitstring','unit'=>'元','title'=>$workerhetitle.'-合作人分额','name'=>'hefee','help'=>'剩余的就是另外一个人的','show'=>array('workerheid >'=>0)),
		array('type'=>'time','title'=>'缴费日期','name'=>'jiao_day','time_type'=>'day'),
		array('type'=>'imgs_show','title'=>'现金分期承诺书','name'=>'fen_file','show'=>array('pay_type'=>1)),
		array('type'=>'array_look','title'=>'分期明细','name'=>'fen_log','show'=>array('pay_type'=>1),
			'list'=>array(
					array('type'=>'string','name'=>'sn','title'=>'期号'),
					array('type'=>'unitstring','unit'=>'元','name'=>'fee','title'=>'当期金额'),
					array('type'=>'string','name'=>'time','title'=>'当期时间'),
			),
		),
		array('type'=>'text','title'=>'来源备注','name'=>'toremark','height'=>60,'read'=>true),
		array('type'=>'radio','title'=>'审批状态','name'=>'status','options'=>'status'),
		array('type'=>'text','title'=>'审批备注','height'=>60,'name'=>'remark'),
	);
	$return['status']=array('待审批','审批通过','审批不通过');
	$return['pay_types']=$this->pay_types;
	$return['daipay_types']=$this->daipay_types;
	$return['htmls']=$htmls;
	exi($return);
}
if($_RQ['op']=='jiaofee2'){
	if($_RQ['postdata']){
		$post=get_postdata();
		if($post['status']==1 && (!$post['fee'] || $post['fee']<=0)){
			exi('请先输入【确认缴纳费用】!','error');
		}
		if($post['status']==1 && !$post['jiao_day']){
			exi('请先输入【缴费日期】!','error');
		}
		$id=$post['id'];
		$data=array(
			'fee'=>$post['fee'],
			'classid'=>$post['classid'],
			'remark'=>trim($post['remark']),
			'pay_type'=>intval($post['pay_type']),
			'daipay_type'=>intval($post['daipay_type']),
			'dai_time'=>intval($post['dai_time']),
			'dai_sn'=>trim($post['dai_sn']),
			'zhanghu'=>trim($post['zhanghu']),
			'status'=>intval($post['status']),
			'jiao_day'=>trim($post['jiao_day']),
			'jiao_time'=>strtotime($post['jiao_day']),
		);
		$data['uniacid']=$_SESSION['uniacid'];
		$data['up_time']=time();
		$data['up_workerid']=$_SESSION['workerid'];
		$this->update('infee_log',$data,array('id'=>$id));
		if($post['status']==1){
			$uplog=array(
				'memberid'=>$post['memberid'],
				'remark'=>'财务审核定金通过',
				'status'=>1,
				'type'=>2,
			);
			$this->model('uplog')->addgenjin_log($uplog);
			if($post['oldstatus']!=10 && $post['oldstatus']!=37  && $post['oldstatus']!=38 && $post['oldstatus']!=43){
				$oldstatus=pdo_getcolumn('jy_yxw_member',array('uniacid'=>$_SESSION['uniacid'],'id'=>$post['memberid']?:$id),'status');
			}
			pdo_update('jy_yxw_member',array('status'=>$oldstatus?:9),array('uniacid'=>$_SESSION['uniacid'],'id'=>$post['memberid']));
			$this->model('feelog')->upfeelog($id,'',1);
		}
		if($post['status']==2){
			$uplog=array(
				'memberid'=>$post['memberid'],
				'remark'=>'财务审核定金不通过',
				'status'=>1,
				'type'=>2,
			);
			$this->model('uplog')->addgenjin_log($uplog);
			if($post['oldstatus']!=10 && $post['oldstatus']!=37  && $post['oldstatus']!=38){
				pdo_update('jy_yxw_member',array('status'=>39),array('uniacid'=>$_SESSION['uniacid'],'id'=>$post['memberid']));
			}
		}
		exi('操作成功！','','goback');
	}
	if($_RQ['id']){
		$feelog=pdo_get('jy_yxw_feelog',array('id'=>$_RQ['id'],'uniacid'=>$_SESSION['uniacid']));
		$item=pdo_get('jy_yxw_infee_log',array('uniacid'=>$_SESSION['uniacid'],'id'=>$feelog['infeeid']));
		$member=pdo_get('jy_yxw_member',array('uniacid'=>$_SESSION['uniacid'],'id'=>$item['memberid']));
		$item['title']=$member['title'];
		$item['mobile']=$member['mobile'];
		$item['cardno']=$member['cardno'];
		$item['xueli']=$member['xueli'];
		$item['oldstatus']=$member['status'];
		$item['classtitle']=pdo_getcolumn('jy_yxw_class',array('uniacid'=>$_SESSION['uniacid'],'id'=>$item['classid']),'title');
		$item['storetitle']=pdo_getcolumn('jy_yxw_store',array('uniacid'=>$_SESSION['uniacid'],'id'=>$item['storeid']),'title');
	}else{
		exi('请先选择记录','error');
	}
	$item['zhanghu']=$item['zhanghu']?:'公户';
	$item['xueli']=$this->xueli_type[$item['xueli']];
	$item['pay_typetitle']=$this->pay_types[$item['pay_type']];
	$item['daipay_typetitle']=$this->daipay_types[$item['daipay_type']];
	$return['item']=$item;	
	$htmls=array(
		'type'=>'edit',
		'desc'=>'售后交定金',
	);
	$htmls['edit']=array(
		array('type'=>'copy','title'=>'所属门店','name'=>'storetitle'),
		array('type'=>'string_three','title1'=>'售后姓名','title2'=>'身份证','title3'=>'手机','name1'=>'title','name2'=>'cardno','name3'=>'mobile','read'=>true),
		array('type'=>'string_three','title1'=>'定金费','title2'=>'缴费方式','title3'=>'缴费渠道','name1'=>'tofee','name2'=>'pay_typetitle','name3'=>'daipay_typetitle','read'=>true),
		array('type'=>'string_three','title1'=>'确认定金费用','title2'=>'到账账户','name1'=>'fee','name2'=>'zhanghu'),
		array('type'=>'time','title'=>'缴费日期','name'=>'jiao_day','time_type'=>'day'),
		array('type'=>'text','title'=>'来源备注','name'=>'toremark','height'=>60,'read'=>true),
		array('type'=>'radio','title'=>'审批状态','name'=>'status','options'=>'status'),
		array('type'=>'text','title'=>'审批备注','name'=>'remark','height'=>60),
	);
	$return['status']=array('待审批','审批通过','审批不通过');
	$return['pay_types']=$this->pay_types;
	$return['daipay_types']=$this->daipay_types;
	$return['htmls']=$htmls;
	exi($return);
}
if($_RQ['op']=='exportold'){
	$return['item']=array();	
	$htmls=array(
		'type'=>'edit',
		'post'=>'set',
		'desc'=>'按月导出数据',
	);
	$htmls['edit']=array(
		array('name'=>'year','title'=>'选择年份','type'=>'select','options'=>'year'),
		array('name'=>'month','title'=>'选择月份','type'=>'select','options'=>'month'),
	);
	$year=intval(date('Y',time()));
	$return['year']=array('0'=>array('id'=>$year-9,'title'=>$year-9),'1'=>array('id'=>$year-8,'title'=>$year-8),'2'=>array('id'=>$year-7,'title'=>$year-7),'3'=>array('id'=>$year-6,'title'=>$year-6),'4'=>array('id'=>$year-5,'title'=>$year-5),'5'=>array('id'=>$year-4,'title'=>$year-4),'6'=>array('id'=>$year-3,'title'=>$year-3),'7'=>array('id'=>$year-2,'title'=>$year-2),'8'=>array('id'=>$year-1,'title'=>$year-1),'9'=>array('id'=>$year,'title'=>$year));
	$return['month']=array('0'=>array('id'=>1,'title'=>1),'1'=>array('id'=>2,'title'=>2),'2'=>array('id'=>3,'title'=>3),'3'=>array('id'=>4,'title'=>4),'4'=>array('id'=>5,'title'=>5),'5'=>array('id'=>6,'title'=>6),'6'=>array('id'=>7,'title'=>7),'7'=>array('id'=>8,'title'=>8),'8'=>array('id'=>9,'title'=>9),'9'=>array('id'=>10,'title'=>10),'10'=>array('id'=>11,'title'=>11),'11'=>array('id'=>12,'title'=>12));
	$return['htmls']=$htmls;
	exi($return);
}
if($_RQ['op']=='set'){
	$post=get_postdata();
	if(!$post['year']){
		exi('请选择年份！','error');
	}
	if(!$post['month']){
		exi('请选择月份！','error');
	}
	$lasttime=strtotime($post['year'].'-'.$post['month'].'-01');
	$url=download_url('jy_yxw/juese14.in/export/lasttime='.$lasttime);
	exi('点确定开始下载','','',$url);
}
if($_RQ['op']=='fenfeeset'){
	if($_RQ['postdata']){
		$post=get_postdata();
		if(!$post['optype']){
			pdo_update('jy_yxw_feelog',array('fee'=>$post['fee']),array('uniacid'=>$_SESSION['uniacid'],'id'=>$post['id']));
			pdo_update('jy_yxw_fenfee_log',array('isfee'=>$post['fee']),array('uniacid'=>$_SESSION['uniacid'],'id'=>$post['fenfeeid']));
		}else{
			pdo_delete('jy_yxw_feelog',array('uniacid'=>$_SESSION['uniacid'],'id'=>$post['id']));
			pdo_delete('jy_yxw_fenfee_log',array('uniacid'=>$_SESSION['uniacid'],'id'=>$post['fenfeeid']));
		}
		exi('操作成功！','','goback');
	}
	$feelog=pdo_get('jy_yxw_feelog',array('uniacid'=>$_SESSION['uniacid'],'id'=>$_RQ['id']));
	$feelog['optype']=0;
	$return['item']=$feelog;
	$htmls=array(
		'type'=>'edit',
		'desc'=>'处理异常',
	);
	$htmls['edit']=array(
		array('name'=>'optype','title'=>'处理方式','type'=>'radio','options'=>'optype'),
		array('name'=>'fee','title'=>'修改后金额','type'=>'unitstring','unit'=>'元','show'=>array('optype'=>0)),
	);
	$return['htmls']=$htmls;
	$return['optype']=array('修改金额','删除该数据');
	exi($return);
}
if($_RQ['op']=='export'){
	$return['params']=array();
	$params=array('status'=>1,'fee OR'=>'fee>0 or fee<=0');
	$params['uniacid']=$_SESSION['uniacid'];
	$params2=array('buy_time OR'=>'buy_time>0 or ding_time>0','uniacid'=>$_SESSION['uniacid']);
	if($_SESSION['storeids']){
		$params['storeid']=$_SESSION['storeids'];
		$params2['storeid']=$_SESSION['storeids'];
	}
	if($_RQ['storeid']){
		$params['storeid']=$_RQ['storeid'];
		$params2['storeid']=$_RQ['storeid'];
		$return['params']['storeid']=$_RQ['storeid'];
	}
	if($_RQ['juese']){
		$return['params']['juese']=$_RQ['juese'];
	}
	if($_RQ['title']){
		$params2['title like']='%'.trim($_RQ['title']).'%';
		$memberids=pdo_getall('jy_yxw_member',$params2,'id','id');
		if($memberids){
			$memberids=array_keys($memberids);
		}else{
			$memberids=-1;
		}
		$params['memberid']=$memberids;
		$return['params']['title']=$_RQ['title'];
	}
	if($_RQ['cardno']){
		$params2['cardno like']='%'.trim($_RQ['cardno']).'%';
		$memberids=pdo_getall('jy_yxw_member',$params2,'id','id');
		if($memberids){
			$memberids=array_keys($memberids);
		}else{
			$memberids=-1;
		}
		$params['memberid']=$memberids;
		$return['params']['cardno']=$_RQ['cardno'];
	}
	if($_RQ['mstatus']){
		$params2['status']=$_RQ['mstatus'];
		$memberids=pdo_getall('jy_yxw_member',$params2,'id','id');
		if($memberids){
			$memberids=array_keys($memberids);
		}else{
			$memberids=-1;
		}
		$params['memberid']=$memberids;
		$return['params']['cardno']=$_RQ['cardno'];
	}
	if($_RQ['jiao_day']){
		$params['jiao_day']=$_RQ['jiao_day'];
		$return['params']['jiao_day']=$_RQ['jiao_day'];
	}
	if($_RQ['zhanghu']){
		$params['zhanghu']=$_RQ['zhanghu'];
		$return['params']['zhanghu']=$_RQ['zhanghu'];
	}
	if($_RQ['type']){
		$params['type']=$_RQ['type']-1;
		$return['params']['type']=$_RQ['type'];
	}
	if($_RQ['worker5id']){
		$params['worker5id']=$_RQ['worker5id'];
		$return['params']['worker5id']=$_RQ['worker5id'];
	}
	if($_RQ['worker6id']){
		$params['worker6id OR']='worker6id='.$_RQ['worker6id'].' or workerheid='.$_RQ['worker6id'];
		$return['params']['worker6id']=$_RQ['worker6id'];
	}
	//创建时间
	if($_RQ['jiao_time']){
		$time_range=cfc('tools')->base64_decode($_RQ['jiao_time'],$_SESSION['base_key_str']);
		$time_range=json_decode($time_range,true);
		$return['params']['jiao_time']=$time_range;
		$params['jiao_time between']=array($time_range['tstart'],$time_range['tend']);
	}
	$list=pdo_getall('jy_yxw_feelog',$params,$fields);
	if($list){
		$fee=$fee2=$fee3=$shouhoufee=$zufee=$peifee=$zhaofee=0;
		foreach($list as &$item){
			$item['member']=$this->model('member')->member_show($item['memberid']);
			$member=pdo_get('jy_yxw_member',array('id'=>$item['memberid'],'uniacid'=>$_SESSION['uniacid']),array('title','status','cardno','worker5id','worker6id','workerheid'));
			$item['cardno']=$member['cardno'];
			$item['mstatus']=$member['status'];
			$item['zhanghu']=$item['zhanghu']?:'公户';
			$item['storetitle']=pdo_getcolumn('jy_yxw_store',array('uniacid'=>$_SESSION['uniacid'],'id'=>$item['storeid']),'title');
			$item['worker5title']=pdo_getcolumn('jy_yxw_worker',array('uniacid'=>$_SESSION['uniacid'],'id'=>$member['worker5id']),'title');
			$item['worker6title']=pdo_getcolumn('jy_yxw_worker',array('uniacid'=>$_SESSION['uniacid'],'id'=>$member['worker6id']),'title');
			if($member['workerheid'] && !$item['workerheid']){
				pdo_update('jy_yxw_feelog',array('workerheid'=>$member['workerheid']),array('id'=>$item['id'],'uniacid'=>$_SESSION['uniacid']));
			}
			$workerhe=pdo_get('jy_yxw_worker',array('uniacid'=>$_SESSION['uniacid'],'id'=>$member['workerheid']),array('juese','title'));
			if($workerhe['title']){
				$item['workerhetitle']=$this->user_juese[$workerhe['juese']].':'.$workerhe['title'];
			}
			$item['createtime']=date('Y-m-d',$item['createtime']);
			$item['jiao_day']=date('Y-m-d',$item['jiao_time']);
			if(!$item['infeeid'] && $item['tuifeeid']){
				$item['infeeid']=pdo_getcolumn('jy_yxw_tuifee_log',array('id'=>$item['tuifeeid'],'uniacid'=>$_SESSION['uniacid']),'infeeid');
			}
			$infee_log=pdo_get('jy_yxw_infee_log',array('id'=>$item['infeeid'],'uniacid'=>$_SESSION['uniacid']));
			$item['infeetype']=$infee_log['type'];
			$item['infeestatus']=$infee_log['status'];
			$item['peifee']=$infee_log['peifee'];
			$item['bufee']=$infee_log['bufee'];
			$item['pay_type']=$infee_log['pay_type'];
			$item['daipay_type']=$infee_log['daipay_type'];
			if($item['type']==1){
				$item['fee']=$item['fee']+$item['bufee'];
				//$item['fee']=0;
			}elseif($item['type']==2){
				$item['fee2']=$item['fee'];
				//$item['fee']=0;
			}elseif($item['type']==3){
				$item['fee3']=$item['fee'];
				//$item['fee']=0;
			}
			$item['zufee']=$item['zufee']>0?$item['zufee']:price($item['fee']*16/100,'int');
			$fee +=$item['fee'];
			$fee2 +=$item['fee2'];
			$fee3 +=$item['fee3'];
			$shouhoufee +=$item['shouhoufee'];
			$zufee +=$item['zufee'];
			$peifee +=$item['peifee'];
			$zhaofee +=$item['zhaofee'];
			$item['pay_type']=$this->pay_types[$item['pay_type']];
			$item['daipay_type']=$this->daipay_types[$item['daipay_type']];
			$item['type']=$this->feelog_type[$item['type']];
		}
		$fee=price($fee,'int');
		$fee2=price($fee2,'int');
		$fee3=price($fee3,'int');
		$shouhoufee=price($shouhoufee,'int');
		$zufee=price($zufee,'int');
		$peifee=price($peifee,'int');
		$zhaofee=price($zhaofee,'int');
		$list[]=array('storetitle'=>'合计','fee'=>$fee,'fee2'=>$fee2,'fee3'=>$fee3,'shouhoufee'=>$shouhoufee,'zufee'=>$zufee,'peifee'=>$peifee,'zhaofee'=>$zhaofee);
	}
	$header=array(
		'storetitle'=>'所属门店',
		'title'=>'姓名',
		'cardno'=>'身份证号',
		'createtime'=>'申请日期',
		'mstatus'=>'状态',
		'type'=>'收费类型',
		'fee2'=>'定金',
		'fee'=>'单费',
		'pay_type'=>'支费方式',
		'daipay_type'=>'贷款渠道',
		'jiao_day'=>'交费日期',
		'zhanghu'=>'到账账户',
		'worker6title'=>'销售员',
		'worker5title'=>'电客',
		'shouhoufee'=>'售后成本',
		'zufee'=>'补贴费',

	);
	model('core/tools')->export2excel($header,$list,'收入明细');
}